﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using SWEN3Application.Classes;
using System.Drawing.Printing;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Reporting.WinForms;


namespace SWEN3Application
{
    public partial class Report : SWEN3Application.MasterForm

    {
       private ArrayList roomlist;
       private ArrayList stafflist;
       private ArrayList Housekeepinglist;
       
   
       

        public Report()
        {
            InitializeComponent();
            
          
        }

        private void tbxavailable_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                dataGridView1.Rows.Clear();
                dataGridView1.ColumnCount = 8;
                dataGridView1.Columns[0].Name = "Room Number";
                dataGridView1.Columns[1].Name = "Room Type";
                dataGridView1.Columns[2].Name = "Room Status";
                dataGridView1.Columns[3].Name = "Room Rate";
                dataGridView1.Columns[4].Name = "Check In";
                dataGridView1.Columns[5].Name = "Check Out";
                dataGridView1.Columns[6].Name = "Booking Number";
                dataGridView1.Columns[7].Name = "Staff ID";


                roomlist = RoomDBManager.GetAllRooms();
                
              
                 roomlist = RoomDBManager.GetAllRooms();

                 for (int i = 0; i < roomlist.Count; i++)
                 {
                     
                     Rooms rm = new Rooms();
                     rm = (Rooms)roomlist[i];
                     if (rm.RoomStatus == "Vacant")
                     {
                         
                         string roomNo = rm.RoomNo.ToString();
                         string roomRates = rm.RoomRates.ToString();
                         string checkin = rm.CheckIn.ToString();
                         string checkout = rm.CheckOut.ToString();
                         string bookingNo = rm.BookingNo.ToString();
                         string[] row = new string[] { roomNo, rm.RoomType, rm.RoomStatus, roomRates, checkin, checkout, bookingNo, rm.StaffId.ToString() };
                         dataGridView1.Rows.Add(row);

                     }
                 }
                    
              
            }
            catch (Exception)
            {
                MessageBox.Show("Data Not found!");
            }

 
    
        }

        private void Report_Load(object sender, EventArgs e)
        {
         
            this.reportViewer2.RefreshReport();
            this.reportViewer3.RefreshReport();
            this.reportViewer1.RefreshReport();
            
            this.reportViewer5.RefreshReport();
        }

        private void tbxoccupied_CheckedChanged(object sender, EventArgs e)
        {
            try
            {

                dataGridView1.Rows.Clear();
                dataGridView1.ColumnCount = 8;
                dataGridView1.Columns[0].Name = "Room Number";
                dataGridView1.Columns[1].Name = "Room Type";
                dataGridView1.Columns[2].Name = "Room Status";
                dataGridView1.Columns[3].Name = "Room Rate";
                dataGridView1.Columns[4].Name = "Check In";
                dataGridView1.Columns[5].Name = "Check Out";
                dataGridView1.Columns[6].Name = "Booking Number";
                dataGridView1.Columns[7].Name = "Staff ID";


                roomlist = RoomDBManager.GetAllRooms();
                
                for (int i = 0; i < roomlist.Count; i++)
                {
                    
                    Rooms rm = new Rooms();
                    rm = (Rooms)roomlist[i];
                    if (rm.RoomStatus == "Occupied")
                    {
                    
                        string roomNo = rm.RoomNo.ToString();
                        string roomRates = rm.RoomRates.ToString();
                        string checkin = rm.CheckIn.ToString();
                        string checkout = rm.CheckOut.ToString();
                        string bookingNo = rm.BookingNo.ToString();
                        string[] row = new string[] { roomNo, rm.RoomType, rm.RoomStatus, roomRates, checkin, checkout, bookingNo, rm.StaffId.ToString() };
                        dataGridView1.Rows.Add(row);
                        
                    }
                   
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Data Not found!");
            }
            
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
           
            try
            {
                dataGridView1.Rows.Clear();
                dataGridView1.ColumnCount = 8;
                dataGridView1.Columns[0].Name = "Room Number";
                dataGridView1.Columns[1].Name = "Room Type";
                dataGridView1.Columns[2].Name = "Room Status";
                dataGridView1.Columns[3].Name = "Room Rate";
                dataGridView1.Columns[4].Name = "Check In";
                dataGridView1.Columns[5].Name = "Check Out";
                dataGridView1.Columns[6].Name = "Booking Number";
                dataGridView1.Columns[7].Name = "Staff ID";


                roomlist = RoomDBManager.GetAllRooms();
               // string RoomStatus = "Schedule for cleaning";
                for (int i = 0; i < roomlist.Count; i++)
                {
                    Rooms rm = new Rooms();
                    rm = (Rooms)roomlist[i];
                    if (rm.RoomStatus == "Schedule For Cleaning")
                    {
                       // Rooms rm = RoomDBManager.GetRoomByStatus(RoomStatus);
                        //dataGridView1.Rows.Clear();
                        string roomNo = rm.RoomNo.ToString();
                        string roomRates = rm.RoomRates.ToString();
                        string checkin = rm.CheckIn.ToString();
                        string checkout = rm.CheckOut.ToString();
                        string bookingNo = rm.BookingNo.ToString();
                        string[] row = new string[] { roomNo, rm.RoomType, rm.RoomStatus, roomRates, checkin, checkout, bookingNo, rm.StaffId.ToString() };
                        dataGridView1.Rows.Add(row);
                        // dataGridView1.Rows.Clear();
                    }
                }

            }
            catch(Exception)
            {
                MessageBox.Show("Data Not Found!");
            }
        }


        private void button10_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView1.Rows.Clear();
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to clear");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application ExcelApp =
          new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook ExcelBook;
            Microsoft.Office.Interop.Excel._Worksheet ExcelSheet;

            int i = 0;
            int j = 0;

            //create object of excel
            ExcelBook = (Microsoft.Office.Interop.Excel._Workbook)ExcelApp.Workbooks.Add(1);
            ExcelSheet = (Microsoft.Office.Interop.Excel._Worksheet)ExcelBook.ActiveSheet;

            
            
            
           for (i = 1; i <= this.dataGridView1.Columns.Count; i++)
            {
                ExcelSheet.Cells[1, i] = this.dataGridView1.Columns[i - 1].HeaderText;
            }

            //export data
            for (i = 1; i <= this.dataGridView1.RowCount; i++)
            {
                for (j = 1; j <= dataGridView1.Columns.Count; j++)
                {
                    ExcelSheet.Cells[i + 1, j] = dataGridView1.Rows[i - 1].Cells[j - 1].Value;
                }
            }

            ExcelApp.Visible = true;

            ExcelSheet = null;
            ExcelBook = null;
            ExcelApp = null;

        }

        private void tbxsearch_Click(object sender, EventArgs e)
        {
           
            
        }

       

        private void tbxList_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView3.ColumnCount = 7;
                dataGridView3.Columns[0].Name = "Staff ID";
                dataGridView3.Columns[1].Name = "Staff Name";
                dataGridView3.Columns[2].Name = "Staff Contact";
                dataGridView3.Columns[3].Name = "Duty Type";
                dataGridView3.Columns[4].Name = "Bank Number";
                dataGridView3.Columns[5].Name = "Date of Birth";
                dataGridView3.Columns[6].Name = "Staff Address";
                // if (stafflist != null)
                // {
                stafflist = StaffsDBManager.GetAllStaffs();
                Staffs s = new Staffs();

                for (int i = 0; i < stafflist.Count; i++)
                {


                    s = (Staffs)stafflist[i];

                    string[] row = new string[] { s.StaffId.ToString(), s.StaffName, s.StaffContact.ToString(), s.DutyType, s.BankNo.ToString(), s.DOB.ToString(), s.StaffAddress };
                    dataGridView3.Rows.Add(row);


                }

            }
            catch (Exception)
            {
                MessageBox.Show("Unable to load");
            }
        }


        private void ROsearch_Click(object sender, EventArgs e)
        {
          
        }

        private void tabPage3_Click(object sender, EventArgs e)
        {
            
           
        }

        private void button8_Click(object sender, EventArgs e)
        {
            try
            {

            DataSet ds1 = new DataSet();

            DataTable dt = new DataTable();

            dt.Columns.Add("StaffId", typeof(string));
            dt.Columns.Add("StaffName", typeof(string));
            dt.Columns.Add("StaffAddress", typeof(string));
            dt.Columns.Add("StaffContact", typeof(string));
            dt.Columns.Add("BankNo", typeof(string));
            dt.Columns.Add("DoB", typeof(string));
            dt.Columns.Add("DutyType", typeof(string));

          
            foreach (DataGridViewRow dgv in dataGridView3.Rows)
            {
                dt.Rows.Add(dgv.Cells[0].Value, dgv.Cells[1].Value, dgv.Cells[2].Value, dgv.Cells[3].Value, dgv.Cells[4].Value, dgv.Cells[5].Value, dgv.Cells[6].Value);
            }

            ds1.Tables.Add(dt);
            ds1.ReadXml("Staff.xml");
            dataGridView3.DataSource = ds1.Tables[0];
            reportViewer3.Visible = true;
            ReportDataSource xx = new ReportDataSource("Staff", ds1.Tables[0]);
            reportViewer3.LocalReport.DataSources.Clear();
            reportViewer3.LocalReport.DataSources.Add(xx);
      
            
            this.reportViewer3.RefreshReport();
            }
            catch(Exception)
            {
                MessageBox.Show("Unable to load");
            }

        }

        private void tbxsearch1_Click_1(object sender, EventArgs e)
        {
            try
            {
                dataGridView4.Rows.Clear();
                dataGridView4.ColumnCount = 10;
                dataGridView4.Columns[0].Name = "Booking Number";
                dataGridView4.Columns[1].Name = "Last Name";
                dataGridView4.Columns[2].Name = "First Name";
                dataGridView4.Columns[3].Name = "Adults Number";
                dataGridView4.Columns[4].Name = "Childs Number";
                dataGridView4.Columns[5].Name = "Phone Number";
                dataGridView4.Columns[6].Name = "Email Address";
                dataGridView4.Columns[7].Name = "Address";
                dataGridView4.Columns[8].Name = "Country";
                dataGridView4.Columns[9].Name = "Remarks";
                // for (int i = 0; i<; i++)
                // {

                int roomNo = Convert.ToInt32(textBox2.Text);
                Rooms rm = RoomDBManager.GetRoomByRoomNo(roomNo);
                int bookingNo = rm.BookingNo;
                BookingList bl = BookingDBManager.GetBookingByBookingNo(bookingNo);

                string[] row = new string[] { bl.BookingNo.ToString(), bl.LastName, bl.FirstName, bl.AdultsNo.ToString(), bl.ChildsNo.ToString(), bl.PhoneNo, bl.EmailAddress, bl.Address, bl.Country, bl.Remarks };
                dataGridView4.Rows.Add(row);
                // }

            }
            catch (Exception)
            {
                MessageBox.Show("Data Not Found");
            }

        }

        private void tbxSearchAll_Click_1(object sender, EventArgs e)
        {
            
                //dataGridView4.Rows.Clear();
                dataGridView4.ColumnCount = 10;
                dataGridView4.Columns[0].Name = "Booking Number";
                dataGridView4.Columns[1].Name = "Last Name";
                dataGridView4.Columns[2].Name = "First Name";
                dataGridView4.Columns[3].Name = "Adults Number";
                dataGridView4.Columns[4].Name = "Childs Number";
                dataGridView4.Columns[5].Name = "Phone Number";
                dataGridView4.Columns[6].Name = "Email Address";
                dataGridView4.Columns[7].Name = "Address";
                dataGridView4.Columns[8].Name = "Country";
                dataGridView4.Columns[9].Name = "Remarks";

                roomlist = RoomDBManager.GetAllRooms();
                Rooms rm = new Rooms();

                for (int i = 0; i < roomlist.Count; i++)
                {
                    rm = (Rooms)roomlist[i];
                    if (rm.RoomStatus == "Occupied")
                    {
                        int bookingNo = rm.BookingNo;
                        BookingList bl = BookingDBManager.GetBookingByBookingNo(bookingNo);


                        string[] row = new string[] { bl.BookingNo.ToString(), bl.LastName, bl.FirstName, bl.AdultsNo.ToString(), bl.ChildsNo.ToString(), bl.PhoneNo, bl.EmailAddress, bl.Address, bl.Country, bl.Remarks };
                        dataGridView4.Rows.Add(row);
                        
                    }
                    else if (rm.RoomStatus == "Vacant")
                    {
                        int bookingNo = rm.BookingNo;
                        BookingList bl = BookingDBManager.GetBookingByBookingNo(bookingNo);


                        string[] row = new string[] { bl.BookingNo.ToString(), bl.LastName, bl.FirstName, bl.AdultsNo.ToString(), bl.ChildsNo.ToString(), bl.PhoneNo, bl.EmailAddress, bl.Address, bl.Country, bl.Remarks };
                        dataGridView4.Rows.Add(row);
                    }
                    else if (rm.RoomStatus == "Schedule For Cleaning")
                    {
                        int bookingNo = rm.BookingNo;
                        BookingList bl = BookingDBManager.GetBookingByBookingNo(bookingNo);


                        string[] row = new string[] { bl.BookingNo.ToString(), bl.LastName, bl.FirstName, bl.AdultsNo.ToString(), bl.ChildsNo.ToString(), bl.PhoneNo, bl.EmailAddress, bl.Address, bl.Country, bl.Remarks };
                        dataGridView4.Rows.Add(row);
                    }

                }
         
        }

        private void reportViewer1_Load(object sender, EventArgs e)
        {
           
        }




        private void tbxloadroomstatus_Click(object sender, EventArgs e)
        {

            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("RoomNo", typeof(string));
            dt.Columns.Add("RoomType", typeof(string));
            dt.Columns.Add("RoomStatus", typeof(string));
            dt.Columns.Add("RoomRates", typeof(string));
            dt.Columns.Add("CheckIn", typeof(string));
            dt.Columns.Add("CheckOut", typeof(string));
            dt.Columns.Add("BookingNo", typeof(string));
            dt.Columns.Add("StaffId", typeof(string));

            string roomno = string.Empty;
            string booking = string.Empty;
            string roomtype = string.Empty;
            string roomstatus = string.Empty;
            string roomrates = string.Empty;
            string checkin = string.Empty;
            string checkout = string.Empty;
            string staffid = string.Empty;
            
            foreach (DataGridViewRow dgv in dataGridView1.Rows)
            {
                 roomno = dgv.Cells[0].Value.ToString();
                
                roomtype = dgv.Cells[1].Value.ToString();
                roomstatus = dgv.Cells[2].Value.ToString();
                roomrates = dgv.Cells[3].Value.ToString();
                checkin = dgv.Cells[4].Value.ToString();
                checkout = dgv.Cells[5].Value.ToString();
                booking = dgv.Cells[6].Value.ToString();
                staffid = dgv.Cells[7].Value.ToString();
                dt.Rows.Add(roomno, roomtype, roomstatus, roomrates, checkin, checkout, booking, staffid);
            }

            ds.Tables.Add(dt);
            ds.ReadXml("RoomStatus.xml");
            dataGridView1.DataSource = ds.Tables[0];
            reportViewer2.Visible = true;
            ReportDataSource xx = new ReportDataSource("Rooms", ds.Tables[0]);
            reportViewer2.LocalReport.DataSources.Clear();
            reportViewer2.LocalReport.DataSources.Add(xx);
            
            this.reportViewer2.RefreshReport();



        }

        private void tbxLoadGuestDetail_Click_1(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("BookingNo", typeof(string));
            dt.Columns.Add("LastName", typeof(string));
            dt.Columns.Add("FirstName", typeof(string));
            dt.Columns.Add("AdultsNo", typeof(string));
            dt.Columns.Add("ChildsNo", typeof(string));
            dt.Columns.Add("PhoneNo", typeof(string));
            dt.Columns.Add("EmailAddress", typeof(string));
            dt.Columns.Add("Address", typeof(string));
            dt.Columns.Add("Remarks", typeof(string));
            dt.Columns.Add("Country", typeof(string));


            foreach (DataGridViewRow dgv in dataGridView4.Rows)
            {

                dt.Rows.Add(dgv.Cells[0].Value, dgv.Cells[1].Value, dgv.Cells[2].Value, dgv.Cells[3].Value, dgv.Cells[4].Value, dgv.Cells[5].Value, dgv.Cells[6].Value, dgv.Cells[7].Value, dgv.Cells[8].Value, dgv.Cells[9].Value);
            }
            ds.Tables.Add(dt);
            ds.ReadXml("GuestDetails.xml");
            dataGridView4.DataSource = ds.Tables[0];
            reportViewer1.Visible = true;
            ReportDataSource xx = new ReportDataSource("GuestDetails", ds.Tables[0]);
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.LocalReport.DataSources.Add(xx);
            reportViewer1.RefreshReport();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView2.ColumnCount = 6;
            dataGridView2.Rows.Clear();
            dataGridView2.Columns[0].Name = "Room Number";
            dataGridView2.Columns[1].Name = "Incharge";
            dataGridView2.Columns[2].Name = "Cleaning Start Time";
            dataGridView2.Columns[3].Name = "Cleaning End Time";
            dataGridView2.Columns[4].Name = "Room Status";
            dataGridView2.Columns[5].Name = "Room Type";
            DateTime dt = DateTime.Today;
            dt.ToShortDateString().ToString();
            DateTime yesterday = dt.AddDays(-1);
            yesterday.ToShortDateString().ToString();
            DateTime tmr = dt.AddDays(1);
            tmr.ToShortDateString().ToString();
            DateTime? cleaningstarttime = null;
            int roomno = 0;
            
            Housekeepinglist = HousekeepingDBManager.GetAllHousekeeping();
            housekeepingOscar newhk = new housekeepingOscar();
            for (int i = 0; i < Housekeepinglist.Count; i++)
            {
                
                newhk = (housekeepingOscar)Housekeepinglist[i];
                cleaningstarttime = newhk.cleaningStartTime;
                roomno = newhk.roomNo;
                if(cleaningstarttime.Equals(dt))
                {
                    housekeepingOscar hk = HousekeepingDBManager.GetRoomByRoomNo(roomno);
                    //housekeepingOscar hk = HousekeepingDBManager.GetByDate(yesterday,tmr);
                    string[] row = new string[] { hk.roomNo.ToString(), hk.inCharge, hk.cleaningStartTime.ToString(), hk.cleaningEndTime.ToString(), hk.roomStatus, hk.roomType };
                   dataGridView2.Rows.Add(row);
                }
            }
        }

        private void Weekreport_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView2.ColumnCount = 6;
            dataGridView2.Rows.Clear();
            dataGridView2.Columns[0].Name = "Room Number";
            dataGridView2.Columns[1].Name = "Incharge";
            dataGridView2.Columns[2].Name = "Cleaning Start Time";
            dataGridView2.Columns[3].Name = "Cleaning End Time";
            dataGridView2.Columns[4].Name = "Room Status";
            dataGridView2.Columns[5].Name = "Room Type";
            DateTime today  = DateTime.Today;
            DateTime startWeek = today.AddDays(1 - Convert.ToInt32(today.DayOfWeek.ToString("d")));
            DateTime endWeek = startWeek.AddDays(6);
            DateTime? cleanningStarttime = null;
            DateTime? cleanningEndtime = null;
            int roomno = 0;
            Housekeepinglist = HousekeepingDBManager.GetAllHousekeeping();
            housekeepingOscar newhk = new housekeepingOscar();
            for (int i = 0; i < Housekeepinglist.Count; i++)
            {
                newhk = (housekeepingOscar)Housekeepinglist[i];
                cleanningStarttime = newhk.cleaningStartTime;
                cleanningEndtime = newhk.cleaningEndTime;
                roomno = newhk.roomNo;
                if (cleanningStarttime>=startWeek&&cleanningEndtime<=endWeek)
                {
                  // DateTime endWeek = startWeek.AddDays(6);
                    housekeepingOscar hk = HousekeepingDBManager.GetRoomByRoomNo(roomno);
                    //housekeepingOscar hk = HousekeepingDBManager.GetByDate(startWeek, endWeek);
                    string[] row = new string[] { hk.roomNo.ToString(), hk.inCharge, hk.cleaningStartTime.ToString(), hk.cleaningEndTime.ToString(), hk.roomStatus, hk.roomType };
                    dataGridView2.Rows.Add(row);
                }
            }

        }

        private void Monthlyreport_CheckedChanged(object sender, EventArgs e)
        {
           
            dataGridView2.ColumnCount = 6;
            dataGridView2.Rows.Clear();
            dataGridView2.Columns[0].Name = "Room Number";
            dataGridView2.Columns[1].Name = "Incharge";
            dataGridView2.Columns[2].Name = "Cleaning Start Time";
            dataGridView2.Columns[3].Name = "Cleaning End Time";
            dataGridView2.Columns[4].Name = "Room Status";
            dataGridView2.Columns[5].Name = "Room Type";
            DateTime today = DateTime.Today;
            DateTime startMonth = today.AddDays(1 - today.Day);
            DateTime endMonth = startMonth.AddMonths(1).AddDays(-1);
            DateTime? cleanningstarttime = null;
           DateTime? cleaningendtime = null;
           int roomno = 0;
            Housekeepinglist = HousekeepingDBManager.GetAllHousekeeping();
            housekeepingOscar newhk = new housekeepingOscar();
            for (int i = 0; i < Housekeepinglist.Count; i++)
            {
                newhk = (housekeepingOscar)Housekeepinglist[i];
                cleanningstarttime = newhk.cleaningStartTime;
                 roomno = newhk.roomNo;
              cleaningendtime = newhk.cleaningEndTime;
                if (cleanningstarttime >= startMonth&&cleaningendtime<=endMonth)
                {
                    housekeepingOscar hk = HousekeepingDBManager.GetRoomByRoomNo(roomno);
                    //housekeepingOscar hk = HousekeepingDBManager.GetByDate(startMonth, endMonth);
                    string[] row = new string[] { hk.roomNo.ToString(), hk.inCharge, hk.cleaningStartTime.ToString(), hk.cleaningEndTime.ToString(), hk.roomStatus, hk.roomType };
                    dataGridView2.Rows.Add(row);
                }
                
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView2.Rows.Clear();
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to clear");
            }
        }

        private void tbxdayRO_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView5.ColumnCount = 8;
            dataGridView5.Rows.Clear();
            dataGridView5.Columns[0].Name = "Room Number";
            dataGridView5.Columns[1].Name = "Room Type";
            dataGridView5.Columns[2].Name = "Room Status";
            dataGridView5.Columns[3].Name = "Room Rate";
            dataGridView5.Columns[4].Name = "Check In";
            dataGridView5.Columns[5].Name = "Check Out";
            dataGridView5.Columns[6].Name = "Booking Number";
            dataGridView5.Columns[7].Name = "Staff ID";

            DateTime dt = DateTime.Today;
           
            string.Format("{0:d}",dt);
            DateTime yesterday = dt.AddDays(-1);
            yesterday.ToShortDateString().ToString();
            DateTime tmr = dt.AddDays(1);
            tmr.ToShortDateString().ToString();


            DateTime? checkin = null;
            //string checkin;
            int roomno = 0;
            decimal count = 0;
            decimal percentage ;
            int occupied = 0;
            string roomstatus;
            roomlist = RoomDBManager.GetAllRooms();
            Rooms nr = new Rooms();
            for (int i = 0; i < roomlist.Count; i++)
            {
                nr = (Rooms)roomlist[i];
                checkin = nr.CheckIn;
               
             
                roomno = nr.RoomNo;
                roomstatus = nr.RoomStatus;
                if (checkin.Equals(dt))
                {
                    if (roomstatus == "Occupied")
                    {
                        Rooms rm = RoomDBManager.GetRoomByRoomNo(roomno);
                        //Rooms rm = RoomDBManager.GetRoomByDate(yesterday,tmr);
                        string[] row = new string[] { rm.RoomNo.ToString(), rm.RoomType, rm.RoomStatus, rm.RoomRates.ToString(), rm.CheckIn.ToString(), rm.CheckOut.ToString(), rm.BookingNo.ToString().ToString(), rm.StaffId.ToString() };
                        dataGridView5.Rows.Add(row);
                        occupied++;
                    }
                }
                count++;

            }
            percentage = ((occupied / count) * 100);
           label8.Text = percentage.ToString("00") + "%";
           label9.Text = count.ToString();
           label11.Text = occupied.ToString();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                dataGridView5.Rows.Clear();
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to clear");
            }
        }

        private void tbxweekRO_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView5.ColumnCount = 8;
            dataGridView5.Rows.Clear();
            dataGridView5.Columns[0].Name = "Room Number";
            dataGridView5.Columns[1].Name = "Room Type";
            dataGridView5.Columns[2].Name = "Room Status";
            dataGridView5.Columns[3].Name = "Room Rate";
            dataGridView5.Columns[4].Name = "Check In";
            dataGridView5.Columns[5].Name = "Check Out";
            dataGridView5.Columns[6].Name = "Booking Number";
            dataGridView5.Columns[7].Name = "Staff ID";
            DateTime today = DateTime.Today;
            DateTime startWeek = today.AddDays(1 - Convert.ToInt32(today.DayOfWeek.ToString("d")));
           DateTime endWeek = startWeek.AddDays(6);
            DateTime? checkin = null;
           DateTime? checkout = null;
           int roomno = 0;
            decimal count1=0 ;
            decimal occupied1=0 ;
            decimal percentage ;
            string roomstatus;
            roomlist = RoomDBManager.GetAllRooms();
            Rooms rm = new Rooms();
            for (int i = 0; i < roomlist.Count; i++)
            {
                rm = (Rooms)roomlist[i];
                checkin = rm.CheckIn;
                checkout = rm.CheckOut;
                roomno = rm.RoomNo;
                roomstatus = rm.RoomStatus;
                if (checkin >= (startWeek)&& checkout <= (endWeek))
                {
                    if (roomstatus == "Occupied")
                    {
                        Rooms rm2 = RoomDBManager.GetRoomByRoomNo(roomno);
                        // Rooms rm2 = RoomDBManager.GetRoomByDate(startWeek,endWeek);
                        string[] row = new string[] { rm2.RoomNo.ToString(), rm2.RoomType, rm2.RoomStatus, rm2.RoomRates.ToString(), rm2.CheckIn.ToString(), rm2.CheckOut.ToString(), rm2.BookingNo.ToString().ToString(), rm2.StaffId.ToString() };
                        dataGridView5.Rows.Add(row);
                        occupied1++;
                    }
                }
                count1++;
            }
            percentage = ((occupied1 / count1) * 100);
            label8.Text = percentage.ToString("00") + "%";
            label9.Text = count1.ToString();
            label11.Text = occupied1.ToString();
        }

        private void tbxmonthRO_CheckedChanged(object sender, EventArgs e)
        {
            dataGridView5.ColumnCount = 8;
            dataGridView5.Rows.Clear();
            dataGridView5.Columns[0].Name = "Room Number";
            dataGridView5.Columns[1].Name = "Room Type";
            dataGridView5.Columns[2].Name = "Room Status";
            dataGridView5.Columns[3].Name = "Room Rate";
            dataGridView5.Columns[4].Name = "Check In";
            dataGridView5.Columns[5].Name = "Check Out";
            dataGridView5.Columns[6].Name = "Booking Number";
            dataGridView5.Columns[7].Name = "Staff ID";
            DateTime today = DateTime.Today;
            DateTime startMonth = today.AddDays(1 - today.Day);
            DateTime endMonth = startMonth.AddMonths(1).AddDays(-1);
          
            string.Format("{0:d}", startMonth);
            string.Format("{0:d}",endMonth);
            int roomno = 0;
            string roomstatus;
            DateTime? checkin = null;
            DateTime? checkout = null;
            decimal count = 0;
            decimal occupied3 = 0;
            decimal percentage;
            roomlist = RoomDBManager.GetAllRooms();
            Rooms rm = new Rooms();
            for (int i = 0; i < roomlist.Count; i++)
            {
                rm = (Rooms)roomlist[i];
                //Rooms rm2 = new Rooms();
                checkin = rm.CheckIn;
                string.Format("{0:d}",checkin);
                string.Format("{0:d}",checkout);
                checkout = rm.CheckOut;
                roomno = rm.RoomNo;
                roomstatus = rm.RoomStatus;
                if (checkin >= (startMonth) && checkout <= (endMonth))
                {
                    if (roomstatus == "Occupied")
                    {
                        Rooms rm2 = RoomDBManager.GetRoomByRoomNo(roomno);
                       
                        string[] row = new string[] { rm2.RoomNo.ToString(), rm2.RoomType, rm2.RoomStatus, rm2.RoomRates.ToString(), rm2.CheckIn.ToString(), rm2.CheckOut.ToString(), rm2.BookingNo.ToString().ToString(), rm2.StaffId.ToString() };
                        dataGridView5.Rows.Add(row);
                        occupied3++;
                    }
                }
                count++;


            }
          
            percentage = ( (occupied3 / count)*100);
            label8.Text = percentage.ToString("00") + "%";
            label9.Text = count.ToString();
            label11.Text = occupied3.ToString();
        }

        private void tbxLoadHK_Click_1(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("RoomNo", typeof(string));
            dt.Columns.Add("InCharge", typeof(string));
            dt.Columns.Add("CleaningStartTime", typeof(string));
            dt.Columns.Add("CleaningEndTime", typeof(string));
            dt.Columns.Add("RoomStatus", typeof(string));
            dt.Columns.Add("RoomType", typeof(string));


            foreach (DataGridViewRow dgv in dataGridView2.Rows)
            {
                
                dt.Rows.Add(dgv.Cells[0].Value,dgv.Cells[1].Value,dgv.Cells[2].Value,dgv.Cells[3].Value,dgv.Cells[4].Value,dgv.Cells[5].Value);
            }


            ds.Tables.Add(dt);
            ds.ReadXml("housekeeping.xml");
            dataGridView2.DataSource = ds.Tables[0];
            reportViewer5.Visible = true;
            ReportDataSource xx = new ReportDataSource("housekeeping", ds.Tables[0]);
            reportViewer5.LocalReport.DataSources.Clear();
            reportViewer5.LocalReport.DataSources.Add(xx);
            this.reportViewer5.RefreshReport();
            

        }

   

     

       
        
        }

        

    }

       
    

